<!-- <script setup>
import { ref } from 'vue'
// import { UpdateArtical, AddArtical } from '@/api/article'
import { ElMessage } from 'element-plus'
const dialogVisible = ref(false)
const formRef = ref()
const formModel = ref({
    cate_name: '',
    cate_alias: ''
})
const IsEdit = ref()
const rules = {
    cate_name: [
        { required: true, message: '请输入分类名称', trigger: 'blur' },
        {
            pattern: /^\S{1,10}$/,
            message: '分类名必须是1-10位的非空字符',
            trigger: 'blur'
        }
    ],
    cate_alias: [
        { required: true, message: '请输入分类别名', trigger: 'blur' },
        {
            pattern: /^[a-zA-Z0-9]{1,15}$/,
            message: '分类别名必须是1-15位的字母数字',
            trigger: 'blur'
        }
    ]
}
const open = (row) => {
    // console.log(row)
    //如果是添加row是空对象 如果是编辑row则带有数据
    dialogVisible.value = true
    formModel.value = { ...row }
    //如果row为空，则重置formModel
}
const emit = defineEmits(['success'])
const onSubmit = async () => {
    await formRef.value.validate()
    IsEdit.value = formModel.value.id
    if (IsEdit.value) {
        await UpdateArtical(formModel.value)
        ElMessage.success('编辑成功')
    } else {
        await AddArtical(formModel.value)
        ElMessage.success('添加成功')
    }

    emit('success')

    dialogVisible.value = false
}
defineExpose({
    open
})
</script>
<template>
    <el-dialog v-model="dialogVisible" :title="formModel.id ? '编辑' : '添加'" width="30%">
        <el-form ref="formRef" :model="formModel" :rules="rules">
            <el-form-item style="padding-right: 20px" label-width="100px" label="分类名称" prop="cate_name">
                <el-input v-model="formModel.cate_name"></el-input>
            </el-form-item>
            <el-form-item style="padding-right: 20px" label-width="100px" label="分类别名" prop="cate_alias">
                <el-input v-model="formModel.cate_alias"></el-input>
            </el-form-item>
        </el-form>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="dialogVisible = false">Cancel</el-button>
                <el-button type="primary" @click="onSubmit"> Confirm </el-button>
            </span>
        </template>
    </el-dialog>
</template>

<style scoped></style> -->
